package com.cskaoyan.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * @BelongProject: mall35th
 * @BelongPackage: com.cskaoyan.shiro
 * @Author: zijin
 * @Createtime: 2021-12-02 星期四 14:27
 * @Description: 解决跨域问题 X-CskaoyanMarket-Token
 */
@Component
public class CustomWebSessionManager extends DefaultWebSessionManager {
    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest request1 = (HttpServletRequest) request;
        String header1 = request1.getHeader("X-CskaoyanMarket-Admin-Token");
        if (header1 != null && !"".equals(header1)){
            return header1;
        }
        String header2 = request1.getHeader("X-CskaoyanMarket-Token");
        if (header2 != null && !"".equals(header2)){
            return header2;
        }
        return super.getSessionId(request,response);
    }
}
